Skip to content

Add demo for JEP 361 - Switch Expressions (Java 14) with JEP 325 & 354 links#320

Merged
AloisSeckar merged 1 commit intoAloisSeckar:masterfrom
Abhineshhh:feat/jep-361-switch-expressions
Oct 27, 2025
Merged

Add demo for JEP 361 - Switch Expressions (Java 14) with JEP 325 & 354 links#320
AloisSeckar merged 1 commit intoAloisSeckar:masterfrom
Abhineshhh:feat/jep-361-switch-expressions

Conversation

@Abhineshhh
Copy link
Contributor

Description

Implements comprehensive demo for JEP 361 - Switch Expressions (Java 14), along with linking classes for the preview versions in Java 12 (JEP 325) and Java 13 (JEP 354).

Closes #318

Changes

Main Demo (Java 14 - JEP 361)

  • Created SwitchExpressionsDemo.java with comprehensive demonstrations of:
    • Arrow labels (case ... ->) vs traditional labels
    • Switch expressions - using switch as an expression to assign values
    • Yield statement - for complex logic blocks within switch expressions
    • Multiple constants per case - comma-separated values
    • Exhaustiveness checking - especially with enums

Linking Classes

  • Java 12 - JEP 325: Created SwitchExpressionsPreview.java (first preview with break statement)
  • Java 13 - JEP 354: Created SwitchExpressionsSecondPreview.java (second preview introducing yield)

Metadata & Registration

  • Updated JDK14Info.json with JEP 361 entry
  • Created JDK13Info.json (first Java 13 metadata file) with JEP 354 entry
  • Updated JDK12Info.json with JEP 325 entry
  • Registered all demos in respective DemoLoader classes

Demo Features Showcased

The JEP 361 demo includes 5 comprehensive demonstrations:

  1. demonstrateArrowLabels() - Contrast between traditional switch with fall-through and new arrow syntax
  2. demonstrateSwitchExpression() - Old vs new way of using switch to assign values
  3. demonstrateYieldStatement() - Using yield for complex logic in switch expressions
  4. demonstrateMultipleConstants() - Multiple case values with practical example
  5. demonstrateExhaustiveness() - Exhaustiveness checking with enum examples

Evolution Across Java Versions

This PR properly documents the evolution of switch expressions:

  • JDK 12 (JEP 325): First preview - arrow labels, switch expressions with break <value>
  • JDK 13 (JEP 354): Second preview - introduced yield statement replacing break <value>
  • JDK 14 (JEP 361): Final version - no changes, became permanent feature

All three classes are properly cross-referenced using @see annotations.

Checklist

  • Follows package structure: org.javademos.java{12,13,14}.jep{325,354,361}
  • Implements IDemo interface with proper info() and demo() methods
  • Uses Markdown-style documentation (///)
  • Added JSON entries to JDK12Info.json, JDK13Info.json, and JDK14Info.json
  • Registered in Java12DemoLoader, Java13DemoLoader, and Java14DemoLoader using JEP numbers as keys
  • Includes @author attribution
  • Working code examples covering all major features
  • Proper cross-references between related JEPs using @see annotations
  • Link classes properly reference final implementation

@AloisSeckar AloisSeckar added the hacktoberfest Counts as submission for Hacktoberfest 2025 label Oct 27, 2025
@AloisSeckar AloisSeckar merged commit 3603ae2 into AloisSeckar:master Oct 27, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hacktoberfest Counts as submission for Hacktoberfest 2025

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JEP 361 - Switch Expressions

2 participants